package com.wdd.atcrowdfunding.potal.service.impl;

import com.wdd.atcrowdfunding.bean.Project;
import com.wdd.atcrowdfunding.manager.dao.ProjectMapper;
import com.wdd.atcrowdfunding.potal.service.ProjectService;
import com.wdd.atcrowdfunding.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public int insert(Project project) {
        return projectMapper.insert(project);
    }

    @Override
    public void insertAlipay(Project project) {
        projectMapper.updateByPrimaryKey(project);
    }

    @Override
    public Page<Project> queryProjectPage(Map<String, Object> paramMap) {
        Page<Project> page = new Page<Project>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = page.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Project> datas = projectMapper.queryList(paramMap);
        page.setDatas(datas);

        Integer totalsize = projectMapper.queryCount(paramMap);
        page.setTotalsize(totalsize);
        return page;
    }

    @Override
    public void updateState(Project project) {
        projectMapper.updateState(project);

    }
}
